package com.shuiyihan.design.structure.proxy.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * 代理增强类
 */
@Component
@Aspect  //标识为一个切面供容器读取
public class CustomAopProxy {
    @Before(value = "execution(* com.shuiyihan.design.structure.proxy.aop.UserService.s*(..))")
    public void before() {
        System.out.println("2.前置通知。。。");
    }

    @Around(value = "execution(* com.shuiyihan.design.structure.proxy.aop.UserService.s*(..))")
    public void around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("1. 环绕前。。。");
        Object value = pjp.proceed();
        System.out.println("7. 环绕后。。。");
    }

    @AfterReturning(value = "execution(* com.shuiyihan.design.structure.proxy.aop.UserService.s*(..))")
    public void afterReturning() {
        System.out.println("4. 后置返回通知。。。");
    }

    @After(value = "execution(* com.shuiyihan.design.structure.proxy.aop.UserService.s*(..))")
    public void after() {
        System.out.println("5. 后置通知。。。");
    }

    @AfterThrowing(value = "execution(* *.s*(..))", throwing = "ex")
    public void afterThrowing(JoinPoint jp, Throwable ex) {
        System.out.println("6. 异常抛出通知" + ex);
    }

}